<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${projectName}</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/tools.js"></script>
<style>
form {
	margin: 0px;
	padding: 0px;
}

input {
	border: 1px solid #cecece;
	color: #3b6998;
	font-size: 14px;
	line-height: 26px;
	height: 26px;
	width: 340px;
	padding-left:5px;
	padding-right:5px;
}

select{
	height:30px;
	width:340px;
	padding-left:5px;
	padding-right:5px;
}
.gr2_bt {
	background: #00bca4;
	text-align: center;
	border: 1px solid #00bca4;
	color: #fff;
	cursor: pointer;
	width: 60px;
}

.gr2_bt:hover {
	background: #00aca4;
}

html {
	height: 88%;
}
.textarea_block{
margin:5px;
width:500px;
height:500px;
padding:5px;
line-height:18px;
}
.title{
	line-height:20px;
	height:20px;
	font-size:12px;
	font-weight:bolder;
	padding:0px;
	margin:0px;
	color:#fff;
	/* 如果浏览器不支持渐变，使用图像作为背景 */
	background: #0a246a;
	/* Webkit: Safari 4-5, Chrome 1-9 */
	background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0a246a),
		to(#a6caf0));
	/* Webkit: Safari 5.1+, Chrome 10+ */
	background: -webkit-linear-gradient(left, #0a246a, #a6caf0);
	/* Firefox 3.6+ */
	background: -moz-linear-gradient(left, #0a246a, #a6caf0);
	/* Opera 11.10+ */
	background: -o-linear-gradient(left, #0a246a, #a6caf0);
	/* IE 10 */
	background: -ms-linear-gradient(left, #0a246a, #a6caf0);
	/* IE < 10 */
	/* 注意：这一行必须写在最后 ,gradientType=0 纵向 1 横向*/
	FILTER: progid:DXImageTransform.Microsoft.Gradient(startColorStr=#0a246a,
		endColorStr=#a6caf0, gradientType=1);
}
.title_text{
	margin-left:5px;
}
.outer_block{
	margin-top:5px;
	margin-left:5px;
	float:left;
	background:#d4d0c8;
}
.table_item{
	background:#ffffff;
	font-size:12px;
	line-height:20px;
	padding-left:10px;
	padding-right:10px;
}
.table_item_choose{
	background:#f00;
	font-weight:bolder;
}
</style>
<script>
document.onkeydown = function(e){
    if(!e) e = window.event;//火狐中是 window.event
    if((e.keyCode || e.which) == 13){
    	submit();
    }
}
$(document).ready(function(){
	/* $(".attr_name").focus(function(){
		
	}); */
});
function addInput(tmp){
	console.log($(tmp))
	var index = $(tmp).attr("attr");
	var newIndex = parseInt(index)+1;
	if($("#"+newIndex).length>0){
		console.log($(tmp));
	}else{
		$("#attr_table tbody").append("<tr id=\""+newIndex+"\"><td>"+newIndex+"</td><td><input type=\"text\" name=\"attr_type\" class=\"attr_type\" onblur=\"fillInput(this)\" /></td><td><input attr=\""+newIndex+"\" type=\"text\" name=\"attr_name\" class=\"attr_name\" onfocus=\"addInput(this)\"/></td></tr>");	
	}
}
function fillInput(tmp){
	var val = $(tmp).val().toLowerCase();
	if(val=="i"){
		$(tmp).val("int");
	}
	if(val=="s"){
		$(tmp).val("String");
	}
	if(val=="d"){
		$(tmp).val("Date");
	}
}
var curTable = "";
function getTables(){
	//alert({"cmd":"getTables","jdbc_driver":$("#jdbc_driver").val(),"jdbc_url":$("#jdbc_url").val(),"jdbc_username":$("#jdbc_username").val(),"jdbc_password":$("#jdbc_password").val()});
	$.ajax({
		url:"do.jsp",
		cache:false,
		type : 'GET',
		dataType : "json",
		data:{"cmd":"getTables","jdbc_driver":$("#jdbc_driver").val(),"jdbc_url":$("#jdbc_url").val(),"jdbc_username":$("#jdbc_username").val(),"jdbc_password":$("#jdbc_password").val()},
		success:function(data){
			$("#table_container").html("");
			for(var i = 0;i<data.length;i++){
				$("#table_container").append("<div class='table_item_container'><span style='float:right;clear:both;line-height:20px;font-size:12px;'>"+(i+1)+"</span>"+"<div class='table_item'>"+data[i]+"</div></div>")
			}
			$(".table_item").click(function(){
				$(".table_item").removeClass("table_item_choose");
				$(this).addClass("table_item_choose");
				curTable = $(this).text();
				getTableDesc(curTable);
			})
		},error:function(){
			alert("error");
		}
	});
}

function getTableDesc(curTable){
	$.ajax({
		url:"do.jsp",
		cache:false,
		type : 'GET',
		dataType : "json",
		data:{"cmd":"getTableDesc","curTable":curTable,"jdbc_driver":$("#jdbc_driver").val(),"jdbc_url":$("#jdbc_url").val(),"jdbc_username":$("#jdbc_username").val(),"jdbc_password":$("#jdbc_password").val()},
		success:function(data){
			$("#table_desc").text("");
			$("#table_desc").text(data.str);
			$("#table_desc2").text(data.pojoCodeStr);
			getSqlserverCreateSQL(data.srcArray,curTable);
			getSinkCode(data.srcArray,curTable);
			getProcessorCode(data.srcArray,curTable);
			getSourceCode(data.srcArray,curTable);
			getTmp1Code(data.srcArray,curTable);
			getTmp2Code(data.srcArray,curTable);
			getSinkBusiness(data.srcArray,curTable);
		},error:function(){
			alert("error");
		}
	});
}

function createCurTable(){
	if(curTable==""){
		alert("请先选择表");
		return;
	}
	$.ajax({
		url:"do.jsp",
		cache:false,
		type : 'GET',
		dataType : "json",
		data:{"cmd":"createCurTable","curTable":curTable,"jdbc_driver":$("#jdbc_driver").val(),"jdbc_url":$("#jdbc_url").val(),"jdbc_username":$("#jdbc_username").val(),"jdbc_password":$("#jdbc_password").val()},
		success:function(data){
			alert("生成完毕!")
		},error:function(){
			alert("error");
		}
	});
}

function createAll(){
	var tables = "";
	$(".table_item").each(function(){
		tables+=$(this).text();
		tables+=","
	})
	if(tables.length==0){
		alert("没有可以生成的表");
		return;
	}
	$.ajax({
		url:"do.jsp",
		cache:false,
		type : 'GET',
		dataType : "json",
		data:{"cmd":"createAll","tables":tables,"jdbc_driver":$("#jdbc_driver").val(),"jdbc_url":$("#jdbc_url").val(),"jdbc_username":$("#jdbc_username").val(),"jdbc_password":$("#jdbc_password").val()},
		success:function(data){
			alert("生成完毕!")
		},error:function(){
			alert("error");
		}
	});
}


function getTmp2Code(arr,curTable){
	var pojoName = curTable.split("_").length>1?curTable.split("_")[1].toLowerCase():curTable.toLowerCase();
	pojoName = firstUp(pojoName);
	var str = "";
	
	
	
	
	 	str+='public String getAccountInsertString ('+pojoName+' obj){\r\n';
		str+='	StringBuffer sb = new StringBuffer();\r\n';
		
		
		 for(var i =0;i<arr.length;i++){
			 var obj = arr[i];
			 var type ="String";
			 str += "sb.append(obj.get"+firstUp(obj[0].toLowerCase())+"());\r\n"
			 if(i!=arr.length-1){
				 str+='	sb.append(divide);\r\n';	 
			 }
		 }
		str+='	sb.append(lineDivide);\r\n';
		str+='		return sb.toString();\r\n';
		str+='	}\r\n';
	
	
	$("#temp2").text(str);
}



function getSqlserverCreateSQL(arr,curTable){
	var pojoName = curTable.split("_").length>1?curTable.split("_")[1].toLowerCase():curTable.toLowerCase();
	var str = "create table "+curTable+" (";
	for(var i=0;i<arr.length;i++){
		var obj = arr[i];
		str += obj[0];
		if("number"==obj[1].toLowerCase()){
			if(obj[3]!=0){
				str += " NUMERIC("+obj[2]+","+obj[3]+") ";
			}else{
				str += " INT ";
			}
		}else if(obj[1].toLowerCase().indexOf("char")!=-1){
			str +=" NVARCHAR("+obj[2]+") ";
		}else if(obj[1].toLowerCase().indexOf("date")!=-1||obj[1].toLowerCase().indexOf("time")!=-1){
			str +=" DATETIME ";
		}
		if(obj[4]==0){
			str += " NOT NULL "
		}
		if(i!=arr.length-1){
			str+=",";
		}
	}
	str += ");\r\n";
	
	str+="-------------hive-------------------\r\n"
		str += "create table "+pojoName+" (";
	for(var i=0;i<arr.length;i++){
		var obj = arr[i];
		str += obj[0];
		if("number"==obj[1].toLowerCase()){
			if(obj[3]!=0){
				str += " DECIMAL ";
			}else{
				str += " BIGINT ";
			}
		}else if(obj[1].toLowerCase().indexOf("char")!=-1){
			str +=" STRING ";
		}else if(obj[1].toLowerCase().indexOf("date")!=-1||obj[1].toLowerCase().indexOf("time")!=-1){
			str +=" DATE ";
		}
		if(i!=arr.length-1){
			str+=",";
		}
	}
	str += ") partitioned by (pt string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE\r\n";
	
	str+="-------------hive load-------------------\r\n";
	str += "alter table "+pojoName+" add partition(pt='"+pojoName+"') location '\"+remoteBasePath+\"/"+pojoName+"/'\r\n";
	
	$("#sqlserver_create").html(str);
}

function getTmp1Code(arr,curTable){
	var pojoName = curTable.split("_").length>1?curTable.split("_")[1].toLowerCase():curTable.toLowerCase();
	pojoName = firstUp(pojoName);
	var str = "";
	 str+='public static int insert'+pojoName+'('+pojoName+' obj) {\r\n';
	 str+='       Connection conn = getConnection();\r\n';
	 str+='       int i = 0;\r\n';
	 str+='       String sql = "insert into '+curTable+' (';
	 
	 for(var i =0;i<arr.length;i++){
		 str+=arr[i][0];
		 if(i<arr.length-1){
			 str+=",";
		 }
	 }
	 
	 str+=') values(';
	 for(var i =0;i<arr.length;i++){
		 str+="?";
		 if(i<arr.length-1){
			 str+=",";
		 }
	 }
	 str+=')";\r\n';
	 str+='       PreparedStatement pstmt =null;\r\n';
	 str+='       try {\r\n';
	 str+='           pstmt = (PreparedStatement) conn.prepareStatement(sql);\r\n';
	 
	 for(var i =0;i<arr.length;i++){
		 var obj = arr[i];
		 var type ="String";
		 
		 if(obj[1].toLowerCase().indexOf("number")!=-1||obj[1].toLowerCase().indexOf("numeric")!=-1){
			 str+="if(obj.get"+firstUp(obj[0].toLowerCase())+"()!=null){\r\n"
			 str+="           pstmt.set";
			 str+="Int("+(i+1)+",obj.get"+firstUp(obj[0].toLowerCase())+"()!=null?obj.get"+firstUp(obj[0].toLowerCase())+"().intValue():null)";
			 str+=";\r\n}else{\r\n";
			 str+="pstmt.setNull("+(i+1)+",Types.NUMERIC);}"
		 }else if(obj[1].toLowerCase().indexOf("date")!=-1||obj[1].toLowerCase().indexOf("time")!=-1){
			 str+="if(obj.get"+firstUp(obj[0].toLowerCase())+"()!=null){\r\n"
			 str+="           pstmt.set";
			 str+="Date("+(i+1)+",obj.get"+firstUp(obj[0].toLowerCase())+"())";
			 str+=";\r\n}else{\r\n";
			 str+="pstmt.setNull("+(i+1)+",Types.DATE);}"
		 }else{
			 str+="if(obj.get"+firstUp(obj[0].toLowerCase())+"()!=null){\r\n"			 
			 str+="           pstmt.set";
			 str+="String("+(i+1)+",obj.get"+firstUp(obj[0].toLowerCase())+"())";
			 str+=";\r\n}else{\r\n";
			 str+="pstmt.setString("+(i+1)+",null);\r\n}\r\n"
		 }
		 
	 }
	 
	 str+='           pstmt.executeUpdate();\r\n';
	 str+='       } catch (SQLException e) {\r\n';
	 str+='          e.printStackTrace();\r\n';
	 str+='      }finally{\r\n';
		 str+=' try {\r\n';
			 str+=' 	  pstmt.close();\r\n';
				 str+='	JdbcUtils_DBCP.release(conn);\r\n';
		 str+='	} catch (SQLException e) {\r\n';
	 str+='		e.printStackTrace();\r\n';
		 str+='	}\r\n';
			 str+=' }\r\n';
	 str+='      return i;\r\n';
	 str+='  }\r\n';
	$("#tmp1_code").text($("#tmp1_code").text()+str);
}

function getSinkCode(arr,curTable){
	var baseName = curTable.split("_").length>1?curTable.split("_")[1].toLowerCase():curTable.toLowerCase();
	pojoName = firstUp(baseName);
	
	var str = "";
	 str+="------------sinkdemo------------\r\n"
	 
	str+=' private '+pojoName+'SinkBusiness '+baseName+'SinkBusiness;\r\n';
	str+='   @StreamListener(Sink.INPUT_'+pojoName+')\r\n';
	str+='    public void sinkMessage'+pojoName+'(Object message){\r\n';
	str+='   	HashMap map = (HashMap) message;\r\n'
	str+='    	int state = (int) map.get("state");\r\n';
	str+='    	List<'+pojoName+'> list = (List) map.get("data");\r\n';
	str+='    	if(ProcessStateConstants.DATA==state){\r\n'
	str+='    		'+baseName+'SinkBusiness.insert'+pojoName+'List(list);\r\n';
	str+='    	}else if(ProcessStateConstants.END==state&&list.size()==0){\r\n';
	str+='    		'+baseName+'SinkBusiness.uploadToHDFS();\r\n';
    str+='    	}\r\n';
	    	
	str+='   }\r\n';	
	 str+='------------sinkdemo------------\r\n'
	 
		    //接收队列1  
	 str+='   String INPUT_'+pojoName+' = "gdSink'+pojoName+'";  \r\n';
	  
	 str+='    @Input(Sink.INPUT_'+pojoName+')  \r\n';
	 str+='    SubscribableChannel input'+pojoName+'();  \r\n';
	 str+="------------properties------------\r\n"
	 
	 str+='spring.cloud.stream.bindings.gdSink'+pojoName+'.destination=PS_'+pojoName+'\r\n';
	 str+='spring.cloud.stream.bindings.gdSink'+pojoName+'.binder=kafka\r\n';
	 str+='spring.cloud.stream.bindings.gdSink'+pojoName+'.group=group-1\r\n';
	 str+='spring.cloud.stream.bindings.gdSink'+pojoName+'.consumer.concurrency=1\r\n';
	 str+='spring.cloud.stream.bindings.gdSink'+pojoName+'.consumer.partitioned=false\r\n';
	 
	 str+="------------insert------------\r\n"
	 str+='public static int insert'+pojoName+'('+pojoName+' obj) {\r\n';
	 str+='       Connection conn = getConnection();\r\n';
	 str+='       int i = 0;\r\n';
	 str+='       String sql = "insert into '+curTable+' (';
	 
	 for(var i =0;i<arr.length;i++){
		 str+=arr[i][0];
		 if(i<arr.length-1){
			 str+=",";
		 }
	 }
	 
	 str+=') values(';
	 for(var i =0;i<arr.length;i++){
		 str+="?";
		 if(i<arr.length-1){
			 str+=",";
		 }
	 }
	 str+=')";\r\n';
	 str+='       PreparedStatement pstmt;\r\n';
	 str+='       try {\r\n';
	 str+='           pstmt = (PreparedStatement) conn.prepareStatement(sql);\r\n';
	 
	 for(var i =0;i<arr.length;i++){
		 var obj = arr[i];
		 var type ="String";
		 str+="           pstmt.set";
		 if(obj[1].toLowerCase().indexOf("number")!=-1||obj[1].toLowerCase().indexOf("numeric")!=-1){
			 str+="Int("+(i+1)+",obj.get"+firstUp(obj[0].toLowerCase())+"().intValue())";
		 }else if(obj[1].toLowerCase().indexOf("date")!=-1||obj[1].toLowerCase().indexOf("time")!=-1){
			 str+="Date("+(i+1)+",obj.get"+firstUp(obj[0].toLowerCase())+"())";
		 }else{
			 str+="String("+(i+1)+",obj.get"+firstUp(obj[0].toLowerCase())+"())";
		 }
		 str+=";\r\n";
	 }
	 
	 str+='           pstmt.executeUpdate();\r\n';
	 str+='           pstmt.close();\r\n';
	 str+='           conn.close();\r\n';
	 str+='       } catch (SQLException e) {\r\n';
	 str+='          e.printStackTrace();\r\n';
	 str+='      }\r\n';
	 str+='      return i;\r\n';
	 str+='  }\r\n';
	 $("#sink_code").text(str);
}

function getProcessorCode(arr,curTable){
	var pojoName = curTable.split("_").length>1?curTable.split("_")[1].toLowerCase():curTable.toLowerCase();
	pojoName = firstUp(pojoName);
	var str = "----------------processor----------------\r\n";
    str += 'String INPUT_'+pojoName+' = "gdSourceProcessor'+pojoName+'";  \r\n';
    str += 'String OUTPUT_'+pojoName+' = "gdProcessorSink'+pojoName+'";  \r\n';
    str += '@Input(Processor.INPUT_'+pojoName+')  \r\n';
    str += 'SubscribableChannel input'+pojoName+'();  \r\n';
    str += '@Output(Processor.OUTPUT_'+pojoName+')  \r\n';
    str += 'MessageChannel output'+pojoName+'();  \r\n';
	str += "----------------properties----------------\r\n";
	str += 'spring.cloud.stream.bindings.gdSourceProcessor'+pojoName+'.destination=SP_'+pojoName+'\r\n';
	str += 'spring.cloud.stream.bindings.gdSourceProcessor'+pojoName+'.binder=kafka\r\n';
	str += 'spring.cloud.stream.bindings.gdSourceProcessor'+pojoName+'.group=group-1\r\n';
	str += 'spring.cloud.stream.bindings.gdSourceProcessor'+pojoName+'.consumer.concurrency=1\r\n';
	str += 'spring.cloud.stream.bindings.gdSourceProcessor'+pojoName+'.consumer.partitioned=false\r\n';

	str += 'spring.cloud.stream.bindings.gdProcessorSink'+pojoName+'.destination=PS_'+pojoName+'\r\n';
	str += 'spring.cloud.stream.bindings.gdProcessorSink'+pojoName+'.binder=kafka\r\n';
	str += "----------------ProcessorDemo----------------\r\n";
	str += '@Transformer(inputChannel = Processor.INPUT_'+pojoName+', outputChannel = Processor.OUTPUT_'+pojoName+')\r\n';
	str += 'public Message<?> transform'+pojoName+'(Message<?> inbound) {\r\n';
	str += '	return inbound;\r\n';
	str += '}\r\n';
	
	$("#processor_code").text(str);
}

function getSinkBusiness(arr,curTable){
	var baseName = curTable.split("_").length>1?curTable.split("_")[1].toLowerCase():curTable.toLowerCase();
	var pojoName = firstUp(baseName);
	
	var str = "";
	str += 'public class '+pojoName+'SinkBusiness extends SinkBusiness{\r\n';
	str += '	//本地相对路径\r\n';
	str += '	private String baseName = "'+baseName+'";\r\n';
	str += '	private String path = basePath +File.separator+ baseName +File.separator;\r\n';
	str += '	private String fileName = baseName +"."+ext;\r\n';
		str += '	public void checkLocalFileExists() throws IOException{\r\n';
		str += '		File f = new File(path + fileName);\r\n';
		str += '	//System.out.println(path+fileName);\r\n';
		str += '		File p = new File(path);\r\n';
		str += '		if(!p.exists()){\r\n';
		str += '			p.mkdirs();\r\n';
		str += '		}\r\n';
		str += '		if(!f.exists()){\r\n';
		str += '			f.createNewFile();\r\n';
		str += '		}\r\n';
		str += '	}\r\n';
		
		str += '	public void uploadToHDFS(){\r\n';
		str += '			try {\r\n';
		str += '			if(HadoopUtil.exists("/"+baseName)&&!HadoopUtil.isDirectory("/"+baseName)){\r\n';
		str += '				HadoopUtil.mkdir("/"+baseName);	\r\n';
		str += '			}\r\n';
		str += '		HadoopUtil.uploadToHDFS(path + fileName,"/"+baseName+"/"+fileName);\r\n';
		str += '		} catch (IOException e) {\r\n';
		str += '			// TODO Auto-generated catch block\r\n';
		str += '			e.printStackTrace();\r\n';
		str += '		}\r\n';
		str += '	}\r\n';
		
		str += '	public void insert'+pojoName+'('+pojoName+' '+baseName+'){\r\n';
		str += '		File f = new File(path+fileName);\r\n';
		str += '		try {\r\n';
		str += '			checkLocalFileExists();\r\n';
		str += '			fs.writeStringToFile(f, get'+pojoName+'InsertString('+baseName+'),"utf-8",true);\r\n';
		str += '		} catch (IOException e) {\r\n';
		str += '			Log.error(ExceptionConstants.WriteError);\r\n';
		str += '			e.printStackTrace();\r\n';
		str += '		}\r\n';
		str += '	}\r\n';
		
		str += '	public void insert'+pojoName+'List(List<'+pojoName+'> '+baseName+'List){\r\n';
		str += '		File f = new File(path+fileName);\r\n';
		str += '	try {\r\n';
		str += '		checkLocalFileExists();\r\n';
		str += '		fs.writeStringToFile(f, get'+pojoName+'InsertString('+baseName+'List),"utf-8",true);\r\n';
		str += '	} catch (IOException e) {\r\n';
		str += '		Log.error(ExceptionConstants.WriteError);\r\n';
		str += '		e.printStackTrace();\r\n';
		str += '	}\r\n';
		str += '	}\r\n';
		
		str += '	public String get'+pojoName+'InsertString (List<'+pojoName+'> '+baseName+'List){\r\n';
		str += '		StringBuffer sb = new StringBuffer();\r\n';
		str += '		for('+pojoName+' obj:'+baseName+'List){\r\n';
		str += '			sb.append(get'+pojoName+'InsertString(obj));\r\n';
		str += '		}\r\n';
		str += '		return sb.toString();\r\n';
		str += '	}\r\n';
		
		str += '	public String get'+pojoName+'InsertString ('+pojoName+' obj){\r\n';
		str += '		StringBuffer sb = new StringBuffer();\r\n';
		str += 'SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);\r\n';
		 for(var i =0;i<arr.length;i++){
			 var obj = arr[i];
			 var type ="String";
			 
			 if(obj[1].toLowerCase().indexOf("date")!=-1||obj[1].toLowerCase().indexOf("time")!=-1){
				 str+=" sb.append(obj.get"+firstUp(obj[0].toLowerCase())+"()==null?\"\":sdf.format(obj.get"+firstUp(obj[0].toLowerCase())+"()));\r\n"
			 }else{
				 str+=" sb.append(obj.get"+firstUp(obj[0].toLowerCase())+"()==null?\"\":obj.get"+firstUp(obj[0].toLowerCase())+"());\r\n"
			 }
			 if(i!=arr.length-1){
				 str += 'sb.append(divide);\r\n';				 
			 }
		 }
		 str += 'sb.append(lineDivide);\r\n';
			
			
		str += '	return sb.toString();\r\n';
		str += '}\r\n';
		str += '}\r\n';
		
		$("#sinkBusiness").text(str);
}

function getSourceCode(arr,curTable){
	var pojoName = curTable.split("_").length>1?curTable.split("_")[1].toLowerCase():curTable.toLowerCase();
	pojoName = firstUp(pojoName);
	var pojoName_lower = pojoName.toLowerCase();
	var str = "----------------source----------------\r\n";
    str += 'String OUTPUT_'+pojoName+' = "gdSourceProcessor'+pojoName+'";  \r\n';
    str += '@Output(Source.OUTPUT_'+pojoName+')  \r\n';
    str += 'MessageChannel output'+pojoName+'();  \r\n';
	str += "----------------properties----------------\r\n";
	str += 'spring.cloud.stream.bindings.gdSourceProcessor'+pojoName+'.destination=SP_'+pojoName+'\r\n';
	str += 'spring.cloud.stream.bindings.gdSourceProcessor'+pojoName+'.binder=kafka\r\n';
	str += "----------------sourceDemo----------------\r\n";
	str += '@InboundChannelAdapter(value = Source.OUTPUT_'+pojoName+')\r\n';
	str += 'public List source'+pojoName+'() {\r\n';
	str += '     List list = DBMgr.process("select * from '+curTable+' where rownum <1001 and etl_state = 0",'+pojoName+'.class);\r\n';
	str += '     DBMgr.process("update '+curTable+' set etl_state = 1 where rownum <1001 and etl_state = 0");\r\n';
	str += '    return list;\r\n';
	str += '}\r\n';
	
	str += "----------------sourceDemo File----------------\r\n";
	
	str += 'boolean '+pojoName_lower+'_isEnd =false;\r\n';
	str += '@InboundChannelAdapter(value = Source.OUTPUT_'+pojoName+')\r\n';
	str += ' public Map source'+pojoName+'() {\r\n';
	str += ' 	HashMap hashMap = new HashMap();\r\n';
	str += '	if('+pojoName_lower+'_isEnd){\r\n';
	str += '		return null;\r\n';
	str += '	}else{\r\n';
	str += '		List<'+pojoName+'> list = FileImportUtil.getImportList("/'+pojoName_lower+'/'+curTable+'.txt", 1000, '+pojoName+'.class);\r\n';
	str += '		if(list.size()==0){\r\n';
	str += ' 			//说明是最后一条了\r\n';
	str += '			'+pojoName_lower+'_isEnd = true;\r\n';
	str += ' 			hashMap.put("state", ProcessStateConstants.END);\r\n';
	str += '			hashMap.put("data", list);\r\n';
	str += '		}else{\r\n';
	str += '			hashMap.put("state", ProcessStateConstants.DATA);\r\n';
	str += 'hashMap.put("data", list);\r\n';
	str += '}\r\n';
	str += 'return hashMap;\r\n';
	str += '}\r\n';
	str += '}\r\n';
	$("#source_code").text(str);
}

//search
$(document).ready(function(){
	$('#search-button').click(function(){
	    var keyWord = $('#key-word').val().trim();
	    //alert(content)
	    $(".table_item_container").show();
	    $(".table_item_container").each(function(){
	    	if($(this).find(".table_item").text().toLowerCase().indexOf(keyWord.toLowerCase())==-1){
	    		$(this).hide();
	    	}
	    })
	})
	$('#clear-button').click(function(){
	    $(".table_item_container").show();
	})
	
	$('#have-button').click(function(){
	    var keyWords = $('#have_key-word').val().trim();
	    //alert(content)
	    
	    var keyWordArray = keyWords.split("|");
	    $(".table_item_container").hide();
	    $(".table_item_container").each(function(){
	    	
	    	for(var i =0;i< keyWordArray.length;i++){
	    		if($(this).find(".table_item").text().toLowerCase()==keyWordArray[i].toLowerCase()){
		    		$(this).show();
		    		break;
		    	}
	    	}
	    })
	})
	$('#have-clear-button').click(function(){
	    $(".table_item_container").show();
	})
})


</script>
</head>

<body style="">
	<div style="height:50px;line-height:50px;">创建POJO生成IBATIS代码</div>
	<form action="code_do.jsp" method="post" target="_blank">
		类名<input name="pojo_name" type="text"/>
		<table id="attr_table">
			<thead>
				<tr>
					<td align="center">序号</td><td align="center">类型</td><td align="center">属性名</td>
				</tr>
			</thead>
			<tbody>
				<tr id="1">
					<td>1</td>
					<td><input type="text" name="attr_type" class="attr_type" onblur="fillInput(this)"/></td>
					<td><input attr="1" type="text" name="attr_name" class="attr_name" onfocus="addInput(this)"/></td>
				</tr>
			</tbody>
		</table>
		<input type="submit" value="确认"/>
	</form>
	<div style="height:10px;line-height:50px;"></div>
	<div style="height:1px;border:1px solid #343434"></div>
	<div style="height:50px;line-height:50px;">根据数据库表结构生成代码</div>
		<table id="">
			<tbody>
				<tr>
					<td>数据库驱动</td>
					<td>
					<select name="jdbc_driver" id="jdbc_driver">
						<option value="com.mysql.jdbc.Driver">com.mysql.jdbc.Driver</option>
						<option value="oracle.jdbc.driver.OracleDriver">oracle.jdbc.driver.OracleDriver</option>
						<option value="net.sourceforge.jtds.jdbc.Driver">net.sourceforge.jtds.jdbc.Driver</option>
					</select>
					</td>
					<td>数据库URL</td>
					<td><input type="text" id="jdbc_url" name="jdbc_url" value="jdbc:mysql://192.168.199.173/test?characterEncoding=utf8&useSSL=true"/></td>
				</tr>
				<script>
					$("#jdbc_driver").change(function(){
						if($("#jdbc_driver").val()=="net.sourceforge.jtds.jdbc.Driver"){
							$("input[name=jdbc_url]").val("jdbc:jtds:sqlserver://localhost:1433/test");
							$("input[name=jdbc_username]").val("sa");
							$("input[name=jdbc_password]").val("12qwaszxQq");
						}else if($("#jdbc_driver").val()=="oracle.jdbc.driver.OracleDriver"){
							$("input[name=jdbc_url]").val("jdbc:oracle:thin:127.0.0.1:1521:ORCL");
							$("input[name=jdbc_username]").val("system");
							$("input[name=jdbc_password]").val("12qwaszxQq");
						}else if($("#jdbc_driver").val()=="oracle.jdbc.driver.OracleDriver"){
							$("input[name=jdbc_url]").val("jdbc:mysql://192.168.199.173/test?characterEncoding=utf8&useSSL=true");
							$("input[name=jdbc_username]").val("root");
							$("input[name=jdbc_password]").val("12qwaszxQq");
						}
					})
				</script>
				<tr>
					<td>登录名</td>
					<td><input type="text" id="jdbc_username" name="jdbc_username" value="root"/></td>
					<td>密码</td>
					<td><input type="text" id="jdbc_password" name="jdbc_password" value="12qwaszxQq"/></td>
				</tr>
				<tr>
					<td colspan="4">
						<input type="button" value="测试连接" onclick="getTables()"/>
						<input type="button" value="生成当前" onclick="createCurTable()"/>
						<input type="button" value="全部生成" onclick="createAll()"/>
					</td>
				</tr>
			</tbody>
		</table>
		<div style="clear:both"></div>
		<div style="width:470px;float:left;">
			<p class="title">
				<span class="title_text"> 用户表</span>
			</p>
			<input id="key-word" class="key-word" placeholder="请输入搜索内容"/>
			<button id="search-button">搜索</button>
			<button id="clear-button">清空</button>
			<div>
				<input id="have_key-word" class="have_key-word" value="TBL_ACCOUNT|TBL_CARD|TBL_CARDUSER|TBL_CARDTYPE|TBL_COMPANYCUSTOMER|TBL_CUSTOMER|TBL_TRADE|TBL_ORGANIZATION" placeholder="请输入搜索内容 例如 tbl_trade|tbl_organization"/>
				<button id="have-button">匹配</button>
				<button id="have-clear-button">清空</button>
			</div>
			<div style="width:470px;height:450px;border:1px solid #cecece;overflow:auto;" id="table_container">
			</div>
		</div>
		
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">表详情</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="table_desc"></textarea>
			</div>
		</div>
		<div style="float:left;width:770px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">POJO详情</span>
				</p>
				<textarea class="textarea_block" style="width:750px;" id="table_desc2"></textarea>
			</div>
		</div>
		
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">sinkBusiness</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="sinkBusiness"></textarea>
			</div>
		</div>
		
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">tmp2</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="temp2"></textarea>
			</div>
		</div>
		
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">sqlserver 建表语句</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="sqlserver_create"></textarea>
			</div>
		</div>
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">sink相关代码</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="sink_code"></textarea>
			</div>
		</div>
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">source相关代码</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="source_code"></textarea>
			</div>
		</div>
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">processor相关代码</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="processor_code"></textarea>
			</div>
		</div>
		
		<div style="float:left;width:570px;margin-left:5px;">
			<div>
				<p class="title">
					<span class="title_text">tmp1</span>
				</p>
				<textarea class="textarea_block" style="width:550px;" id="tmp1_code"></textarea>
			</div>
		</div>
</body>
</html>
